package com.qiaofang.collectmanage.stub.feign.client.impl;

import com.qiaofang.collectmanage.stub.bean.*;
import com.qiaofang.collectmanage.stub.facade.HouseAgentFacade;
import com.qiaofang.collectmanage.stub.facade.OperatorLogFacade;
import com.qiaofang.collectmanage.stub.feign.client.HouseAgentClient;
import com.qiaofang.collectmanage.stub.feign.client.OperatorLogClient;
import com.qiaofang.collectmanage.stub.request.*;
import com.qiaofang.collectmanage.stub.response.SearchHouseAgentPageResponse;
import com.qiaofang.collectmanage.stub.response.SearchOperatorLogPageResponse;
import com.qiaofang.common.constant.CommonResponseCode;
import com.qiaofang.common.exception.BusinessException;
import com.qiaofang.common.model.page.PageDTO;
import com.qiaofang.common.response.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author li.yi
 * @date 2018年8月18日
 */
@Service("operatorLogClient")
public class OperatorLogClientImpl implements OperatorLogClient {

	@Autowired
	private OperatorLogFacade operatorLogFacade;


	@Override
	public void batchSaveOperatorLog(List<SaveOperatorLogDTO> saveOperatorLogDTOs) {
		SaveOperatorLogRequest request = new SaveOperatorLogRequest();
		request.setSaveOperatorLogDTOs(saveOperatorLogDTOs);
		CommonResponse response = operatorLogFacade.batchSaveOperatorLog(request);
		if (!CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
			throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
		}

	}


	@Override
	public SearchOperatorLogPageDTO searchOperatorLogPage(PageDTO pageDTO,SearchOperatorLogPostDTO searchOperatorLogPostDTO) {
		SearchOperatorLogPageRequest request = new SearchOperatorLogPageRequest();
		request.setPageDTO(pageDTO);
		request.setSearchOperatorLogPostDTO(searchOperatorLogPostDTO);
		SearchOperatorLogPageResponse response = operatorLogFacade.searchOperatorLogPage(request);
		if (CommonResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
			return response.getData();
		} else {
			throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
		}
	}

}
